<template>
  <div class="main">
    <div class="header">
      <el-button type="primary" round @click="waitOrder">待接取</el-button>
      <el-button type="success" round @click="progressOrder">派送中</el-button>
      <el-button type="warning" round @click="finishOrder">已接收</el-button>
    </div>
    <div class="content">
      <el-table :data="tableData">
        <el-table-column label="订单号" prop="orderId"></el-table-column>
        <el-table-column label="餐品名" prop="dishName"></el-table-column>
        <el-table-column label="单价" prop="dishPrice"></el-table-column>
        <el-table-column label="数量" prop="quantity"></el-table-column>
        <el-table-column label="买家id" prop="userId"></el-table-column>
        <el-table-column label="收货地点" prop="placeName"></el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import {getFinishOrder, getProgressOrder, getWaitOrder} from "@/http/api/restaurant";
import cookie from "js-cookie";

export default {
  name: "Order",
  data() {
    return {
      tableData: [],
    }
  },
  methods: {

    // 获取待接取订单
    async waitOrder() {
      let result = await getWaitOrder({
        restaurantId: cookie.get('restaurantId')
      })
      if (result.code === 0) {
        this.tableData = result.data
      } else {
        this.$message.warning(result.message)
      }
    },

    // 获取进行中订单
    async progressOrder() {
      let result = await getProgressOrder({
        restaurantId: cookie.get('restaurantId')
      })
      if (result.code === 0) {
        this.tableData = result.data
      } else {
        this.$message.warning(result.message)
      }
    },

    // 获取已完成订单
    async finishOrder() {
      let result = await getFinishOrder({
        restaurantId: cookie.get('restaurantId')
      })
      if (result.code === 0) {
        this.tableData = result.data
      } else {
        this.$message.warning(result.message)
      }
    },
  },
  async mounted() {
    await this.waitOrder()
  }
}
</script>

<style scoped>

</style>